﻿@{
    ViewBag.Title = "Detail";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<style>
    .ui-layout .center-Panel {
        margin-right: 0px;
        margin-top: 0px;
        padding-top: 5px;
        border-top: 0px;
    }
</style>
<script>
    var keyValue = request('keyValue');
    var State = 0;
    $(function () {
        InitialPage();
        GetGrid();
        GetGrid1();
    });
    //初始化页面
    function InitialPage() {
        $('#layout').css("height", $(window).height());
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 441.5);
                $('#gridTable1').setGridWidth(($('.gridPanel').width()));
                $("#gridTable1").setGridHeight($(window).height() - 441.5);
            }, 200);
            e.stopPropagation();
        });

        if (!!keyValue) {
            $.SetForm({
                url: "../../FinancialManage/EnergyMeterFee/GetFrom",
                param: { keyValue: keyValue },
                success: function (data) {
                    State = data.data.State;
                    if (!!data.data1)
                        $(".form").SetWebControls(data.data1);
                    if (!!data.data2)
                        GetGrid(data.data2);
                    if (!!data.data3)
                        GetGrid1(data.data3);
                    GetGridAudit();
                }
            });
        }

    }

    function GetGrid(data) {
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 441.5,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "EnergyMeterInstanceId", name: "EnergyMeterInstanceId", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "State", name: "State", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "表编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "PSMemo", width: 150, align: "left", sortable: false },
                { label: "上次抄表期间", name: "LastBatchDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表时间", name: "LastScaleDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表读数", name: "LastScaleNum", width: 100, align: "left", sortable: false },
                {
                    label: "本次抄表期间", name: "BatchDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : $("#BatchDate").val();
                    }
                },
                {
                    label: "本次抄表时间", name: "ScaleDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : "@DateTime.Now.ToString("yyyy-MM-dd")";
                    }
                },
                { label: "本次抄表读数", name: "ScaleNum", width: 100, align: "left", sortable: false },
                { label: "用量", name: "Volume", width: 100, align: "left", sortable: false },
                {
                    label: "调整用量", name: "AdjustVolume", width: 100, align: "left", sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : 0;
                    }
                },
                { label: "单价", name: "UnitPrice", width: 80, align: "left", sortable: false },
                { label: "金额", name: "Price", width: 100, align: "left", sortable: false },
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false
        });
        $gridTable[0].addJSONData(data);
    }

    function GetGrid1(data) {
        var $gridTable = $("#gridTable1");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 441.5,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "EnergyMeterInstanceId", name: "EnergyMeterInstanceId", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "State", name: "State", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "费项名称", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "客户名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "房产名称", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "用量", name: "Quantity", width: 150, align: "left", sortable: false },
                { label: "单价", name: "UnitPrice", width: 100, align: "left", sortable: false },
                { label: "系数", name: "Coefficient", width: 100, align: "left", sortable: false },
                { label: "应收金额", name: "ReceiveAmount", width: 100, align: "left", sortable: false },
                { label: "已付金额", name: "ReceivedAmount", width: 100, align: "left", sortable: false },
                { label: "税率", name: "TaxRate", width: 100, align: "left", sortable: false },
                { label: "税金", name: "TaxAmount", width: 100, align: "left", sortable: false },
                { label: "应收年月", name: "ReceiveMonth", width: 100, align: "left", sortable: false },
                { label: "权责年月", name: "AccMonth", width: 100, align: "left", sortable: false },
                { label: "计费开始时间", name: "BeginDate", width: 100, align: "left", sortable: false },
                { label: "计费终止时间", name: "EndDate", width: 100, align: "left", sortable: false },
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false
        });
        $gridTable[0].addJSONData(data);
    }

    //加载审核记录
    function GetGridAudit() {
        var $gridTable = $("#gridTable2");
        $gridTable.jqGrid({
            url: "../../FinancialManage/EnergyMeterFee/GetAudit?BillId=" + keyValue,
            datatype: "json",
            height: 110,
            autowidth: true,
            unwritten: false,
            mtype: "POST",
            colModel: [
                    { label: 'ID', name: 'Id', hidden: true },
                    { label: "级数", name: "Level", width: 90, align: "left", sortable: false },
                    {
                        label: "执行类别", name: "RoleType", width: 100, align: "left", sortable: false,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (cellvalue) {
                                case 2: return "角色";
                                case 1: return "岗位";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: "执行角色", name: "RoleId", width: 100, align: "left", sortable: false,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (rowObject.RoleType) {
                                case 2: return !!cellvalue ? top.clientroleData[cellvalue]["FullName"] : "";
                                case 1: return !!cellvalue ? top.clientpostData[cellvalue]["FullName"] : "";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: "审批结果", name: "AuditState", width: 100, align: "left", sortable: true,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (cellvalue) {
                                case 2: return "不通过";
                                case 1: return "通过";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: '审批人', name: 'AuditMan', width: 100, align: "left", sortable: false,
                    },
                    { label: "审批时间", name: "AuditTime", width: 200, align: "left", sortable: false },
                    { label: "审批意见", name: "AuditMemo", width: 110, align: "left", sortable: false }
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            gridComplete: function () {
                if (State == 1 || State == 2)
                    GetIsShow();
            }
        });
    }

    function GetIsShow() {
        var obj = $("#gridTable2").jqGrid("getRowData");
        var Level = 1;
        $(obj).each(function (i, n) {
            if (!n["AuditTime"]) {
                if (Level > n["Level"])
                    Level = n["Level"];
            }
        });
        $.SetForm({
            url: "../../SystemManage/Setting/GetIsShow",
            param: { TypeName: "抄表单", Level: Level - 1 },
            dataType: "text",
            success: function (data) {
                var Audit = JSON.parse(data);
                var Html = "";
                if (Audit.OK) {
                    $("#AuditState").show();
                    NowLevel = Audit.NowLevel;
                    if (Audit.HasHandling == 1) {
                        var HandleConditionJson = JSON.parse(Audit.HandleConditionJson);
                        for (var i = 0; i < HandleConditionJson.length; i++) {
                            if (HandleConditionJson[i].Type == "1") {
                                Html += "<td class=\"formTitle\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"checkbox\" class=\"WorkAudit\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                                Html += "<td class=\"formValue\" >" + HandleConditionJson[i].FieldName + "</td>";
                            }
                            if (HandleConditionJson[i].Type == "2") {
                                Html += "<td class=\"formTitle\">" + HandleConditionJson[i].FieldName + "<font face=\"宋体\">*</font></td>";
                                Html += "<td class=\"formValue\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"text\" class=\"form-control WorkAudit\" isvalid=\"yes\" checkexpession=\"NotNull\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                            }
                        }
                        $("#WorkAudit").html(Html);
                        if (ShowType == 1) {
                            $("#WorkAudit").html("");
                        }
                    }
                }
                else
                    $("#AuditState").hide();
            }
        });
    }

    function btn_Audit(AuditState) {
        var queryJson = $("#AuditState").GetWebControls(keyValue);
        var obj = $("#gridTable2").jqGrid("getRowData");
        var Level = 99999;
        $(obj).each(function (i, n) {
            if (!n["AuditTime"]) {
                if (Level > n["Level"])
                    Level = n["Level"];
            }
        })
        queryJson["AuditState"] = AuditState;
        queryJson["Level"] = Level;
        queryJson["BillId"] = keyValue;
        queryJson["AuditType"] = 0;
        $.SaveForm({
            url: "../../FinancialManage/EnergyMeterFee/AuditForm?keyValue=" + keyValue,
            param: queryJson,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
<div class="ui-layout" id="layout" style="width: 100%;">
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="gridPanel">
                <table class="form">
                    <tr>
                        <th class="formTitle">抄表单号</th>
                        <td class="formValue">
                            <input id="Code" type="text" class="form-control" disabled="disabled" />
                        </td>
                        <th class="formTitle">批次号</th>
                        <td class="formValue">
                            <input id="BatchNo" type="text" class="form-control" disabled="disabled" />
                        </td>
                        <th class="formTitle">抄表期间<font face="宋体">*</font></th>
                        <td class="formValue">
                            <input id="BatchDate" type="text" class="form-control" disabled="disabled" />
                        </td>
                        <th class="formTitle">权责期间<font face="宋体">*</font></th>
                        <td class="formValue">
                            <input id="RightDate" type="text" class="form-control" disabled="disabled" />
                        </td>
                    </tr>
                    <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="8"></td></tr>
                    <tr>
                        <td colspan="4" style="border-right: 1px solid #cecece;">
                            <div class="panel-Title" style="border: 0px; text-align: center; background-color: #fff;">抄表明细</div>
                            <table id="gridTable"></table>
                        </td>
                        <td colspan="4">
                            <div class="panel-Title" style="border: 0px; text-align: center; background-color: #fff; ">财务明细</div>
                            <table id="gridTable1"></table>
                        </td>
                    </tr>
                    <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="8"></td></tr>
                    <tr style="padding-left: 5px; padding-top: 5px; margin-left: 5px; margin-top: 5px;">
                        <td colspan="8" style="padding-left: 5px; padding-top: 5px;">
                            <div class="panel-Title" style="border: 0px; text-align: center; background-color: #fff; ">审核记录</div>
                            <table id="gridTable2"></table>
                        </td>
                    </tr>
                    <tr style=" height: 20px; border-bottom: 1px dashed #cecece;" hidden><td colspan="8"></td></tr>
                    <tr id="AuditState" hidden style="padding-left:5px;padding-top:5px;margin-left:5px;margin-top:5px;">
                        <td class="formTitle" style="padding-left: 5px; padding-top: 5px;">审批意见：</td>
                        <td class="formValue" colspan="3" style="padding-left: 5px; padding-top: 5px;"><input id="AuditMemo" class="form-control" type="text" /></td>
                        <td class="formValue" colspan="4" style="padding-left: 5px; padding-top: 5px;">
                            <a id="lr-addRule" class="btn btn-success btn-xs" style="width:150px;height:28px;" onclick="btn_Audit(1)"><i class="fa fa-plus"></i>&nbsp;同意</a>
                            <a id="lr-deleteRule" class="btn btn-danger btn-xs" style="width: 150px; height: 28px;" onclick="btn_Audit(2)"><i class="fa fa-trash-o"></i>&nbsp;不同意</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="form-button" id="wizard-actions">
    <a id="btn_Colose" class="btn btn-danger" onclick="dialogClose()">关闭</a>
</div>
